package com.mlink.ai.chat.network

import com.mlink.ai.chat.network.bean.ApiResponse
import com.mlink.ai.chat.network.bean.request.GetAnswerRequest
import com.mlink.ai.chat.network.bean.request.ReGetAnswerRequest
import com.mlink.ai.chat.network.bean.request.RegisterUserRequest
import com.mlink.ai.chat.network.bean.request.SubscribeRequest
import com.mlink.ai.chat.network.bean.response.GetAnswerResponse
import com.mlink.ai.chat.network.bean.response.SubscribeResponse
import com.mlink.ai.chat.ui.viewmodel.FeedbackRequest
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.FieldMap
import retrofit2.http.FormUrlEncoded
import retrofit2.http.GET
import retrofit2.http.Multipart
import retrofit2.http.POST
import retrofit2.http.Part
import retrofit2.http.PartMap
import retrofit2.http.QueryMap
import retrofit2.http.Url

interface ChatApi {

    /**
     * 用户注册
     */
    @POST("api/v1/RegisterUser")
    suspend fun doRegisterUser(@Body request: RegisterUserRequest): ApiResponse<Any>

    /**
     * 获取回答结果
     */
    @POST("api/v1/Chat")
    suspend fun getAnswer(@Body request: GetAnswerRequest): ApiResponse<GetAnswerResponse>

    /**
     * 轮询请求结果
     */
    @POST("api/v1/Result")
    suspend fun reGetAnswer(@Body request: ReGetAnswerRequest): ApiResponse<GetAnswerResponse>

    /**
     * 订阅
     */
    @POST("api/v1/Subscribe")
    suspend fun doSubscribe(@Body request: SubscribeRequest): ApiResponse<SubscribeResponse>

    /**
     * 刷新订阅信息
     */
    @POST("api/v1/Restore")
    suspend fun doRestore(@Body request: SubscribeRequest): ApiResponse<SubscribeResponse>

    /**
     * 上传图文
     */
    @Multipart
    @POST("api/v1/ImageCaption")
    suspend fun uploadImageCaption(
        @PartMap map: HashMap<String, RequestBody>,
        @Part file: MultipartBody.Part?
    ): ApiResponse<GetAnswerResponse>

    @FormUrlEncoded
    @POST("api/v1/ImageCaption")
    suspend fun uploadImageCaptionWithoutPhoto(@FieldMap map: HashMap<String, Any>): ApiResponse<GetAnswerResponse>

    /**
     * 轮询获取图文结果
     */
    @GET("api/v1/ResultImageCaption")
    suspend fun getImageCaptionResult(@QueryMap map: HashMap<String, Any>): ApiResponse<GetAnswerResponse>

    /**
     * 获取反馈 token
     */
    @FormUrlEncoded
    @POST
    suspend fun getFeedbackToken(
        @Url url: String,
        @FieldMap map: HashMap<String, Any>
    ): ApiResponse<Any>

    /**
     * Feedback 附件上传
     */
    @Multipart
    @POST
    suspend fun uploadFile(
        @Url url: String,
        @PartMap map: HashMap<String, RequestBody>,
        @Part file: MultipartBody.Part?
    ): ApiResponse<Any>

    /**
     * Feedback
     */
    @POST
    suspend fun feedback(
        @Url url: String,
        @Body map: FeedbackRequest
    ): ApiResponse<Any>
}

object Api {
    val chatApi: ChatApi by lazy {
        RetrofitUtil.retrofit.create(ChatApi::class.java)
    }
}